<html>
<head>
    <meta charset="UTF-8">
    <script type='text/javascript' src='../resources/js/jquery-1.8.3.min.js'
            charset='utf-8'></script>
</head>


<body>

<div id="main">
    <!-- 标题 -->
    <div class="row">
        <div class="col-md-12">
            <h1>管理员注册</h1>
        </div>
    </div>

    <form class="form-horizontal" role="form">
        <div class="form-group">
            <label class="col-sm-1 control-label">用户名</label>
            <div class="col-sm-3">
                <input type="text" class="form-control" id="username"  name="username" placeholder="请输入用户名">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-1 control-label">密码</label>
            <div class="col-sm-3">
                <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-1 control-label">授权码</label>
            <div class="col-sm-3">
                <input type="password" class="form-control" id="authCode" name="authCode" placeholder="请输入授权码">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-1 col-sm-3">
                <button type="submit" id="register" class="btn btn-default">注册</button>
            </div>
        </div>
    </form>
</div>

</body>

<script>

    jQuery(document).ready(function(){

        //绑定otp的click时间用于向后端发送获取手机验证码的请求
        $("#register").on("click",function(){
            var username = $("#username").val();
            var password = $("#password").val();
            var authCode = $("#authCode").val();
            if(username == null || username == ""){
                alert("用户名不能为空");
                return false;
            }
            if(password == null || password == ""){
                alert("密码不能为空");
                return false;
            }
            if(authCode == null || authCode == ""){
                alert("授权码不能为空");
                return false;
            }

            var registerVo = {
                username: $("#username").val(),
                password: $("#password").val(),
                authCode: $("#authCode").val()
            };
            // var loginVo = {};
            // loginVo.username = $("#username").val();
            // loginVo.password = $("#password").val();

            console.log("loginVo " + JSON.stringify(registerVo) )

            $.ajax({
                type:"POST",
                contentType:"application/json;charset=utf-8",
                url:"http://localhost:8080/signIn",
        /*        data:{
                    loginVo: JSON.stringify(loginVo)
                    //"authCode":$("#authCode").val()
                },*/
                data: JSON.stringify(registerVo),
                //xhrFields:{withCredentials:true},
                success:function(data){
                    if(data.code == "0"){
                        alert("注册成功");
                        window.location.href="./login.html";
                    }else{
                        alert("注册失败，原因为"+data.data);
                    }
                },
                error:function(data){
                    alert("注册失败，原因为"+data.data);
                }
            });
            return false;
        });


    });


</script>

</html>